﻿<UserControl x:Class="GW2PAO.Views.WvWTracker.VerticalWvWObjectiveView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:converters="clr-namespace:GW2PAO.Style.Converters"
             xmlns:core="clr-namespace:GW2PAO.PresentationCore;assembly=GW2PAO.PresentationCore"
             mc:Ignorable="d" d:DesignHeight="80" d:DesignWidth="58"
             TextOptions.TextFormattingMode="Display">

    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="../../Style/ResourceLibrary.xaml" />
            </ResourceDictionary.MergedDictionaries>

            <BooleanToVisibilityConverter x:Key="BoolToVisibility"/>
            <converters:ObjectiveTypeImageSrcConverter x:Key="ObjTypeConverter" />
            <converters:WvWMapConverter x:Key="MapConverter" />
            <converters:WorldColorConverter x:Key="WorldColorConverter" />
            <converters:EventStateConverter x:Key="StateConverter" />
            <converters:TimespanConverter x:Key="TimeConverter" />

        </ResourceDictionary>
    </UserControl.Resources>

    <UserControl.Style>
        <Style TargetType="UserControl">
            <Setter Property="Height" Value="82" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding UserSettings.AreTimeDistancesShown}" Value="False">
                    <DataTrigger.Setters>
                        <Setter Property="Height" Value="60" />
                    </DataTrigger.Setters>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </UserControl.Style>

    <UserControl.ContextMenu>
        <ContextMenu>
            <MenuItem Header="Hide" Command="{Binding HideCommand}" />
            <Separator />
            <MenuItem Header="Copy Chat Code" Command="{Binding CopyChatCodeCommand}" />
            <Separator />
            <MenuItem Header="Copy Under Attack Text" Command="{Binding CopyUnderAttackTextCommand}" />
            <MenuItem Header="Copy Enemy Headed Towards Text" Command="{Binding CopyEnemyHeadedToTextCommand}" />
            <MenuItem Header="Copy Player Headed Towards Text" Command="{Binding CopyPlayerHeadedToTextCommand}" />
            <MenuItem Header="Copy RI Timer Text" Command="{Binding CopyRITextCommand}" />
        </ContextMenu>
    </UserControl.ContextMenu>
    
    <UserControl.ToolTip>
        <StackPanel Orientation="Vertical">
            <core:OutlinedTextBlock Fill="Orange" FontSize="12" Text="{Binding Name}"/>
            <StackPanel Orientation="Horizontal">
                <core:OutlinedTextBlock Margin="0,0,5,0" Text="Owned By:" />
                <core:OutlinedTextBlock Margin="0,0,2,0" Text="{Binding WorldOwnerName}"/>
            </StackPanel>
            <StackPanel Orientation="Horizontal">
                <core:OutlinedTextBlock Margin="0,0,5,0" Text="Points:" />
                <core:OutlinedTextBlock Margin="0,0,2,0" Text="{Binding Points}"/>
            </StackPanel>
        </StackPanel>
    </UserControl.ToolTip>

    <!--Note: DataContext is set by the DungeonTrackerView-->
    <Border Name="MainBorder" CornerRadius="0" Margin="0,0,0,0" Padding="5,2,5,0" BorderThickness="1,0,0,0">

        <Border.Effect>
            <DropShadowEffect ShadowDepth="0" Opacity="0" BlurRadius="50"
                              Color="{Binding WorldOwner, Converter={StaticResource WorldColorConverter}}" />
        </Border.Effect>

        <Border.Triggers>
            <EventTrigger SourceName="OwnerTextblock" RoutedEvent="Binding.TargetUpdated">
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation To="1"          Storyboard.TargetName="MainBorder"
                                                         Storyboard.TargetProperty="(Effect).Opacity"
                                                         Duration="00:00:00.5"/>
                        <DoubleAnimation To="0.25"       Storyboard.TargetName="MainBorder"
                                                         Storyboard.TargetProperty="(Effect).Opacity"
                                                         Duration="00:00:00.5"
                                                         BeginTime="00:00:0.5"/>
                        <DoubleAnimation To="1"          Storyboard.TargetName="MainBorder"
                                                         Storyboard.TargetProperty="(Effect).Opacity"
                                                         Duration="00:00:00.5"
                                                         BeginTime="00:00:01"/>
                        <DoubleAnimation To="0.25"       Storyboard.TargetName="MainBorder"
                                                         Storyboard.TargetProperty="(Effect).Opacity"
                                                         Duration="00:00:00.5"
                                                         BeginTime="00:00:01.5"/>
                        <DoubleAnimation To="1"          Storyboard.TargetName="MainBorder"
                                                         Storyboard.TargetProperty="(Effect).Opacity"
                                                         Duration="00:00:00.5"
                                                         BeginTime="00:00:02"/>
                        <DoubleAnimation To="0"          Storyboard.TargetName="MainBorder"
                                                         Storyboard.TargetProperty="(Effect).Opacity"
                                                         Duration="00:00:00.5"
                                                         BeginTime="00:00:02.5"/>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </Border.Triggers>
        
        <Border.BorderBrush>
            <LinearGradientBrush Opacity="0.65" StartPoint="0,0" EndPoint="0,1">
                <GradientStop Color="#00FFA500" Offset="0"/>
                <GradientStop Color="#FFFFA500" Offset="0.5"/>
                <GradientStop Color="#00FFA500" Offset="1"/>
            </LinearGradientBrush>
        </Border.BorderBrush>

        <Border.Background>
            <SolidColorBrush Color="#01FFFFFF" />
        </Border.Background>

        <Grid Margin="0,0,0,0">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="15" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="53" />
            </Grid.ColumnDefinitions>

            <!--Objective Image-->
            <Image Grid.Row="0"
                   Height="25" Width="25"
                   VerticalAlignment="Center" HorizontalAlignment="Center">
                <Image.Source>
                    <MultiBinding Converter="{StaticResource ObjTypeConverter}">
                        <Binding Path="Type"/>
                        <Binding Path="WorldOwner"/>
                    </MultiBinding>
                </Image.Source>
            </Image>

            <!--Objective Name/Location (e.g. N, NW, SW, etc or the objective's short name) -->
            <core:OutlinedTextBlock Grid.Row="1"
                                    VerticalAlignment="Center" HorizontalAlignment="Center">
                <core:OutlinedTextBlock.Style>
                    <Style TargetType="core:OutlinedTextBlock" BasedOn="{StaticResource {x:Type core:OutlinedTextBlock}}">
                        <Setter Property="Text" Value="{Binding Location}"/>
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding UserSettings.AreShortNamesShown}" Value="True">
                                <Setter Property="Text" Value="{Binding ShortName}"/>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </core:OutlinedTextBlock.Style>
            </core:OutlinedTextBlock>

            <StackPanel Orientation="Vertical" Grid.Row="2"
                        VerticalAlignment="Center" HorizontalAlignment="Center"
                        Margin="0,5,0,0">
                
                <!--Distance-->
                <StackPanel Orientation="Horizontal" Grid.Row="2"
                            VerticalAlignment="Center" HorizontalAlignment="Center"
                            Visibility="{Binding UserSettings.AreTimeDistancesShown, Converter={StaticResource BoolToVisibility}}"
                            Margin="0,0,0,5">

                    <core:OutlinedTextBlock Margin="0,0,3,0">
                        <core:OutlinedTextBlock.Style>
                            <Style TargetType="core:OutlinedTextBlock" BasedOn="{StaticResource {x:Type core:OutlinedTextBlock}}">
                                <Setter Property="Text" Value=""/>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding UserSettings.DistanceUnits}" Value="TimeDistance">
                                        <Setter Property="Text" Value="Dist:"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </core:OutlinedTextBlock.Style>
                    </core:OutlinedTextBlock>

                    <core:OutlinedTextBlock Fill="White">
                        <core:OutlinedTextBlock.Style>
                            <Style TargetType="core:OutlinedTextBlock" BasedOn="{StaticResource {x:Type core:OutlinedTextBlock}}">
                                <Setter Property="Text" Value="{Binding DistanceFromPlayer}"/>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding UserSettings.DistanceUnits}" Value="TimeDistance">
                                        <Setter Property="Text" Value="{Binding DistanceFromPlayer, Converter={StaticResource TimeConverter}, ConverterParameter=true}"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </core:OutlinedTextBlock.Style>
                    </core:OutlinedTextBlock>

                    <core:OutlinedTextBlock VerticalAlignment="Center" HorizontalAlignment="Left">
                        <core:OutlinedTextBlock.Style>
                            <Style TargetType="core:OutlinedTextBlock" BasedOn="{StaticResource {x:Type core:OutlinedTextBlock}}">
                                <Setter Property="Text" Value=" ft"/>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding UserSettings.DistanceUnits}" Value="Meters">
                                        <Setter Property="Text" Value=" m"/>
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding UserSettings.DistanceUnits}" Value="TimeDistance">
                                        <Setter Property="Text" Value=""/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </core:OutlinedTextBlock.Style>
                    </core:OutlinedTextBlock>
                </StackPanel>

                <!--RI Timer Value (if any), will hide/show based with trigger-->
                <StackPanel Orientation="Horizontal" Grid.Row="3"
                            VerticalAlignment="Center" HorizontalAlignment="Center"
                            Visibility="{Binding IsRIActive, Converter={StaticResource BoolToVisibility}}">
                    <core:OutlinedTextBlock Margin="0,0,3,0"
                                            Text="RI:" />
                    <core:OutlinedTextBlock Name="TimerValueTextBlock"
                                            Text="{Binding TimerValue, Converter={StaticResource TimeConverter}, ConverterParameter=true}" />
                </StackPanel>
            </StackPanel>

            <!--Dummy textblock for flashing the item when the owner changes -->
            <TextBlock Name="OwnerTextblock" Opacity="0" Visibility="Collapsed" Text="{Binding WorldOwner, NotifyOnTargetUpdated=True}" />
        </Grid>
    </Border>
</UserControl>
